/**
 * LMK0482X: TI-LMK0482X-时钟抖动消除器
 */
#pragma once

#include <stdint.h>
#include "mcu.h"

// 表示寄存器参数结束
#define LMK0482X_REG_END 0xFFFFFFFF

/**
 * LMK0482x family devices are programmed using 24-bit registers. Each register consists of a 1-bit command field
 * (R/W), a 2-bit multi-byte field (W1, W0), a 13-bit address field (A12 to A0), and an 8-bit data field (D7 to D0). The
 * contents of each register is clocked in MSB first (R/W), and the LSB (D0) last.
 */

#define LMK0482X_ID_DEVICE_TYPE      6
#define LMK0482X_ID_PROD             0xD05B
#define LMK0482X_ID_MASKREV_LMK04821 36
#define LMK0482X_ID_MASKREV_LMK04826 37
#define LMK0482X_ID_MASKREV_LMK04828 32
#define LMK0482X_ID_VNDR             0x5104
 
/// @brief LMK0482X 统一驱动 数据结构
typedef struct _unidrv_lmk0482x {
    mcu_spi_t *spi;            // 使用的 SPI 接口: <= 20MHz
    func_gpio_write_out_t nss; // SPI 片选信号
    
    // 4 个 IO 信号的读写驱动回调函数
    func_gpio_write_out_t sync_out;
    func_gpio_write_out_t rst_out;
    func_gpio_read_in_t ld1_in;
    func_gpio_read_in_t ld2_in;
    
    uint8_t id_maskrev; // 芯片型号/版本，见: LMK0482X_ID_MASKREV_LMK0482?
} unidrv_lmk0482x_t;

/// @brief LMK0482X 初始化
/// @param dev 设备句柄。
/// @param regs 寄存器指令，[23:23]=读(1)/写(0)控制, [20:8]=ADDR[12:0]为寄存器地址, [7:0]=REGD[7:0]为寄存器值。0xFFFFFFFF表示寄存数组结束。
std_err_t unidrv_lmk0482x_init(
    unidrv_lmk0482x_t *dev,
    uint32_t regs1[],
    uint32_t regs2[],
    uint32_t regs3[],
    uint32_t regs5[],
    uint32_t regs6[]);
